﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="listenMessages.aspx.cs" Inherits="SampleVoiceForum.listenMessages" %>
<%@ Import Namespace="DatabaseLayer" %>

<%      
    int count = Convert.ToInt16(Request.QueryString["count"]);
%>
<?xml version="1.0" encoding="UTF-8"?> 
<vxml version = "2.1">
<property name="inputmodes" value="dtmf"/> 
<form id="DocumentForm" scope="document">
<grammar scope="document" type="text/gsl"> 
      <![CDATA[ 

      MYRULE 
      [ 
      [dtmf-9]        {<MySlot "DTMF nine">} 
      ] 
      ]]>
       
</grammar> 

<filled namelist="MySlot"> 
  <goto next="Home.aspx"/> 
 </filled> 

<field name="field1">
<prompt bargein="true" bargeintype="hotword" timeout="100ms">
 <% if (count == 0)
        Response.Write("Press 9 anytime to go to main menu"); 
 %>

</prompt>
                    
<noinput>
<goto next='#listenMessageForm' />
</noinput>

<nomatch>
<goto next='#listenMessageForm' />
</nomatch>
</field>

<!-- this empty field matching 
        the form grammar's slot is required 
--> 
<field name="MySlot"/>
</form>

<form id="listenMessageForm"> 
  <var name="count" />
 
  <block>
    <%
        
        DatabaseFunctions objectDatabaseFunctions = new DatabaseFunctions();
        objectDatabaseFunctions.addAnalytics((String)Session["sessionId"], (String)Session["callerId"], "listenMessages.aspx", "Entered listenMessages.aspx", null);
        String recordingURL = objectDatabaseFunctions.getModeratedFileForPlayback((String)Session["sessionId"]);
        
        if (recordingURL == null)
        {
            Response.Write("<prompt> Database Error </prompt> <goto next='Home.aspx'/>");
        }
        else if(recordingURL.Equals(""))
        {
            if(count == 0)
                Response.Write("<prompt> No messages availaible. Thank you for listening the messages at Sample Voice Forum.</prompt> <goto next='Home.aspx'/>");
            else
                Response.Write("<prompt> Thank you for listening the messages at Sample Voice Forum.</prompt> <goto next='Home.aspx'/>");
        }
        else
        {
            count++;
                %>
                 <prompt> Message <% Response.Write(count);%> </prompt><break time="100ms" />
                 <audio src="<%Response.Write(recordingURL);%>" fetchtimeout="10s"> 
                  Failure occured in fetching audio.
                 </audio>
                 <break time="1s" />
                 <assign expr="'<%Response.Write(count); %>'" name="count" />
                 <submit next="ListenMessages.aspx" namelist="count"/>
                <%
             objectDatabaseFunctions.insertCallerListenData((String)Session["sessionId"], recordingURL);
             objectDatabaseFunctions.addAnalytics((String)Session["sessionId"], (String)Session["callerId"], "listenMessages.aspx", "Listened URL", recordingURL);
        
        }
    %>
     
 </block> 
 </form> 
</vxml>